<?php
/*As we can see that we already mentioned this file in index.js because 
 * through this file we are going access mySql database to show it in the 
 * jqGrid.
 */
$page=$_GET["page"];
$rows=$_GET["rows"];

include 'db.php';
$db = new db();

        $result= $db->query("SELECT * FROM user_names");
        //This is the part for the search option in grid but for now i am changing it to work on some other application.
    $search = $_GET["find"];
    if($search == "")
        $result= $db->query("SELECT * FROM user_names");
    else
        $result= $db->query("SELECT * FROM user_names WHERE user LIKE '%$search%'");
    $totalpages= ceil(mysql_num_rows($result)/$rows);

    if($totalpages<$page){
        $page=1;
    }

    $responce->page=$page;
    $responce->total=$totalpages;
    $i=0;
    $count=0;

    while($row_variable = mysql_fetch_array($result)){
        if($i >=($page-1)*$rows && $i <= $page*$rows-1){
            $responce->rows[$count]['cell'] = array($row_variable['id'],$row_variable['user'],$row_variable['password']);
            $i++;
        }
        $count++;
    }
// THIS IS NOT CLEAR TO UNDERSTAND ASK FOR IT?
    /*while($tablerow = mysql_fetch_array($result)){
        if($i >= ($page-1)*$rows && $i <= $page*$rows-1){
                $responce->rows[$count]['cell']=array($tablerow['id'],$tablerow['user'],$tablerow['password']);
                $count++;
            }
            $i++;
    }*/
    $responce->records=$count;
    echo json_encode($responce);
?>
